package com.re6g3y.game.Tile.Hexagonal;

import com.badlogic.gdx.math.Vector2;

/**
 * 获取坐标位置默认内接圆半径为为1
 */
final public class HexagonalIterator {
    private int x,y;
    final public int getX() {
        return x;
    }
    final public int getY() {
        return y;
    }

    final static float sqrt3= (float)Math.sqrt(3);
    final public Vector2 getPositionCenter(){
        return new Vector2(y*sqrt3, (x * 2 +y));
    }

    final public float getPositionCenterX() {
        return y*sqrt3;
    }

    final public float getPositionCenterY() {
        return x * 2 +y;
    }

    /**
     * 转化x，y为long long Transform Xy
     *
     * @param x
     * @param y
     * @return
     */
    HexagonalIterator(int x, int y){
        this.x=x;
        this.y=y;
    }

    HexagonalIterator(long l){
        x=(int)(l>>>32);
        y=(int)(l);
    }

    HexagonalIterator(HexagonalIterator iter){
        x=iter.x;
        y=iter.y;
    }

    final public HexagonalIterator set(HexagonalIterator iter){
        x=iter.x;
        y=iter.y;
        return this;
    }

    final public HexagonalIterator set(long l){
        x=(int)(l>>>32);
        y=(int)(l);
        return this;
    }

    final public HexagonalIterator addX(int n){
        y+=n;
        x-=n;
        return this;
    }
    final public HexagonalIterator addXY(int n){
        y+=n;
        return this;
    }
    final public HexagonalIterator addY(int n){
        x+=n;
        return this;
    }
    final public HexagonalIterator addYZ(int n){
        x+=n;
        y-=n;
        return this;
    }
    final public HexagonalIterator addZ(int n){
        y-=n;
        return this;
    }
    final public HexagonalIterator addZX(int n){
        x-=n;
        return this;
    }
    final public long getVal(){
        long t = x;
        t <<= 32;
        t |= y&0xffffffffL;
        return t;
    }
    final public int dist(HexagonalIterator another){
        int a=Math.abs(x-another.x);
        int b=Math.abs(y-another.y);
        int c=Math.abs((x+y)-(another.x+another.y));
        if(a>c&&a>b)return b+c;
        if(b>c)return a+c;
        return a+b;
    }

    final public HexagonalIterator cpy(){
        return new HexagonalIterator(x,y);
    }
}
